package com.example.a14110100409.yuejiandemo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.adapter.TeaAdapter;
import com.example.a14110100409.yuejiandemo.javabean.TeaList;
import com.example.a14110100409.yuejiandemo.model.Model;
import com.example.a14110100409.yuejiandemo.service.ActImpls;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * A simple {@link Fragment} subclass.
 */
public class TeacherFragment extends Fragment {
    private List<TeaList> list;
    private Context context;
    private TeaAdapter adapter;
    private View view;
    private RecyclerView recyclerView;
    public TeacherFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_teacher, container, false);
        init();
        event();
        return view;
    }
    public void init()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.L_teacher);
        context=getActivity();

    }
    public void event()
    {
        Retrofit retrofit= Model.getConn();
        ActImpls impls=retrofit.create(ActImpls.class);
        Call<List<TeaList>> call=impls.getTeaList(1);
        call.enqueue(new Callback<List<TeaList>>() {
            @Override
            public void onResponse(Call<List<TeaList>> call, Response<List<TeaList>> response) {
                list=response.body();
                adapter=new TeaAdapter(context,list);
                LinearLayoutManager manager=new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setLayoutManager(manager);
            }

            @Override
            public void onFailure(Call<List<TeaList>> call, Throwable t) {

            }
        });
    }
}

